package practica3;

public class Consumidor extends Thread {

	private static Buffer buffer;
	private String name;
	private int oat;
	private boolean l;
	
	public Consumidor(Buffer buffertw,String name,int objectes_a_treure,boolean lent_i_aleatori){
		buffer = buffertw;
		this.name = name;
		oat = objectes_a_treure;
		l = lent_i_aleatori;
	}
	
	public void run() {
		for(int i = 0; i < oat; i++){
				System.err.println("Consumidor "+name+" ha extret l'objecte '"+buffer.get(this)+"'.");		
			try {
				if(l) sleep(1000+(long)(Math.random()*1000));
				else sleep(10);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		System.err.println("Consumidor "+name+" ha acabat de recollir tots els seus elements.");
	}
	
}
